// #ifdef H5
import globalPopup from './globalPopup.vue'
// #endif
const install = Vue => {
	Vue.prototype.$popup = {
		show(params) {
			let that = this;
			params.show =true;
			// Vue.store 传递参数
			Vue.prototype.$store.dispatch('updatePopupConfig',params)
			// #ifdef APP-PLUS
			uni.navigateTo({
				url: '/components/globalPopup/globalPopup',
				events:{
					confirm: function(data) {
					  params.confirm && params.confirm()
					},
					cancel: function(data) {
					  params.cancel && params.cancel()
					}
				}
			})
			// #endif
			// #ifdef H5
				const PopupVue = Vue.extend(globalPopup);
				const popupDom = new PopupVue();
				popupDom.vm = popupDom.$mount();
				const lastEl = document.body.lastElementChild;
				if(lastEl.id !== 'popup-box'){
					setTimeout(()=>{
						document.body.appendChild(popupDom.vm.$el)
					})
				}
			// #endif
		}
	}
}

export default install;
